package org.darcy.config;

import javax.annotation.PostConstruct;

import org.darcy.config.property.AppProperties;
import org.darcy.framework.blog.tag.ArticleTags;
import org.darcy.framework.blog.tag.CustomTags;
import org.darcy.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import com.jagregory.shiro.freemarker.ShiroTags;

import freemarker.template.TemplateModelException;

/**
 * freemarker配置类
 */
@Configuration
public class FreeMarkerConfig {

	@Autowired
	protected freemarker.template.Configuration configuration;
	
	@Autowired
	protected CustomTags customTags;
	
	@Autowired
	protected ArticleTags articleTags;
	
	@Autowired
	private SysConfigService configService;
	
	@Autowired
	private AppProperties appProperties;

	/**
	 * 添加自定义标签
	 */
	@PostConstruct
	public void setSharedVariable() {
		configuration.setSharedVariable("zhydTag", customTags);
		configuration.setSharedVariable("articleTag", articleTags);
		try {
			configuration.setSharedVariable("config", configService.getConfigs());
			configuration.setSharedVariable("appInfo", appProperties);
			// shiro标签
			configuration.setSharedVariable("shiro", new ShiroTags());
		} catch (TemplateModelException e) {
			e.printStackTrace();
		}
	}
}
